package springframework.beans.exceptions;

public abstract class NestedRuntimeException extends RuntimeException implements HasRootCause {

    private Throwable rootCause;

    public NestedRuntimeException(String message) {
        super(message);
    }

    public NestedRuntimeException(String message, Throwable rootCause) {
        super(message);
        this.rootCause = rootCause;
    }

    @Override
    public Throwable getRootCause() {
        return rootCause;
    }

    @Override
    public String getMessage() {
        return this.rootCause == null ? super.getMessage() : super.getMessage() + "; nested exception is: \n\t" + this.rootCause.toString();
    }


}
